#include <gmlib/block_cipher_mode/gcm_mode.h>
#include <gmlib/sm4/sm4.h>

#include <cstring>
#include <stdexcept>

#include "test.h"

using namespace sm4;
using namespace block_cipher_mode;
using SM4GcmEncryptor = GcmEncryptor<SM4>;
using SM4GcmDecryptor = GcmDecryptor<SM4>;

static std::uint8_t user_key[16] = {
    0xf0, 0xb5, 0xe6, 0xc0, 0x65, 0xf7, 0x76, 0x96,
    0xae, 0xf0, 0xbe, 0x58, 0x25, 0x35, 0x90, 0xe5,
};
static std::uint8_t iv[16] = {
    0x48, 0xa9, 0x8b, 0x0f, 0x97, 0xcd, 0x39, 0xc9,
    0x3a, 0xf3, 0xe4, 0xab, 0x42, 0x91, 0x57, 0x3b,
};
static std::uint8_t aad[16] = {
    0xcb, 0x93, 0x41, 0xdb, 0x3e, 0xe5, 0x33, 0x3f,
    0xaa, 0x99, 0xc4, 0x3c, 0x6a, 0x89, 0xc7, 0x5b,
};
static std::uint8_t pt[1024] = {
    0xf3, 0xd7, 0x21, 0x91, 0xa8, 0x6b, 0x15, 0x10, 0xf5, 0xd1, 0xc5, 0x36,
    0x81, 0x7e, 0x1a, 0x07, 0x46, 0xf9, 0xc8, 0x4b, 0xd5, 0x7e, 0x1d, 0xba,
    0x71, 0xa8, 0x54, 0xa3, 0xa5, 0x37, 0x65, 0x0c, 0xc6, 0xa9, 0xcb, 0x3c,
    0xa7, 0x8f, 0xd7, 0xfe, 0x29, 0xd1, 0x3a, 0x43, 0xdf, 0xea, 0x00, 0x9f,
    0x03, 0xf9, 0xf7, 0x2f, 0x0f, 0xf1, 0xf1, 0x08, 0xc7, 0xbf, 0x51, 0x7f,
    0xc9, 0x19, 0x36, 0x67, 0xa0, 0x4e, 0x7c, 0x34, 0xe4, 0x24, 0x9b, 0x79,
    0x2d, 0x3d, 0x62, 0x0f, 0xd8, 0x82, 0xc8, 0x16, 0x27, 0x23, 0x9a, 0x12,
    0xbe, 0x85, 0x6c, 0xab, 0xc8, 0x54, 0xb9, 0xd8, 0x74, 0x30, 0x05, 0xeb,
    0x9d, 0x16, 0xd3, 0x1b, 0x99, 0xb0, 0x5f, 0x54, 0x06, 0x6c, 0xf7, 0x0a,
    0x40, 0x17, 0xd0, 0x6b, 0xa3, 0x1f, 0xed, 0xf2, 0xc9, 0xfc, 0x03, 0x74,
    0x7a, 0x8b, 0xd7, 0x5f, 0xef, 0x3f, 0x63, 0x0a, 0x71, 0x85, 0x6f, 0x6b,
    0x67, 0x46, 0x7f, 0x8b, 0x59, 0x03, 0xc2, 0x4c, 0x9a, 0xc1, 0x9a, 0x7e,
    0x92, 0x9d, 0xff, 0x46, 0x27, 0x0a, 0xef, 0x57, 0xa3, 0x78, 0x36, 0x19,
    0x27, 0x8d, 0xa0, 0x13, 0x24, 0x46, 0x63, 0x08, 0xf2, 0x7e, 0x7c, 0xf6,
    0xf0, 0xa3, 0x54, 0xa3, 0x1a, 0x53, 0x92, 0x20, 0x64, 0x00, 0x95, 0xa6,
    0xb3, 0x62, 0xdb, 0x80, 0xe8, 0xf8, 0xb9, 0xd5, 0xeb, 0x35, 0x0b, 0x57,
    0xd0, 0x81, 0x0d, 0x80, 0xf3, 0x2f, 0xce, 0xdc, 0x15, 0xa2, 0xb0, 0xea,
    0x86, 0x2d, 0x22, 0x94, 0x4b, 0xbb, 0xf8, 0x74, 0x4a, 0xfc, 0xb2, 0xde,
    0xe5, 0x12, 0x5b, 0xe0, 0xdd, 0xa3, 0x71, 0x0c, 0xdb, 0x51, 0x41, 0xbc,
    0x33, 0x54, 0x27, 0x80, 0x87, 0x0b, 0xe2, 0xb5, 0x2a, 0x74, 0x78, 0x22,
    0x57, 0x8b, 0x45, 0xf5, 0x54, 0x92, 0x5e, 0x82, 0xaf, 0x4a, 0x84, 0x6c,
    0xe1, 0xb4, 0x8a, 0xb8, 0x24, 0x94, 0x1c, 0xa3, 0x32, 0x1e, 0x0e, 0xfc,
    0x44, 0x5e, 0x7d, 0x73, 0x97, 0x0c, 0x3d, 0xfe, 0xa1, 0x34, 0x15, 0x62,
    0x18, 0x0a, 0x89, 0x7f, 0x41, 0x3a, 0xd6, 0x0b, 0x9a, 0x11, 0x05, 0x28,
    0x37, 0xe4, 0x00, 0x1a, 0xee, 0x55, 0xe4, 0x50, 0xa9, 0x71, 0x3a, 0x05,
    0xdd, 0xcf, 0x24, 0x42, 0xa6, 0x42, 0xf0, 0x8a, 0x9f, 0x03, 0x1b, 0xf2,
    0x11, 0x00, 0xf4, 0x6d, 0x33, 0x14, 0xf2, 0xb5, 0xd0, 0x2c, 0xed, 0xf1,
    0x83, 0x7e, 0xcd, 0x13, 0xd3, 0xfe, 0xc7, 0x1f, 0xe3, 0x02, 0x7b, 0xf9,
    0xe2, 0x1b, 0xdb, 0x61, 0x0e, 0x8d, 0x22, 0xef, 0xbf, 0x20, 0x1c, 0xd1,
    0x0f, 0x03, 0xef, 0xff, 0xc0, 0x5d, 0xb7, 0xb7, 0xdf, 0xb6, 0x3e, 0xf7,
    0xb1, 0xa6, 0x52, 0xfd, 0x28, 0xfa, 0xa9, 0xbd, 0x34, 0xd7, 0xf0, 0x18,
    0xdc, 0xa2, 0xaa, 0xe8, 0x7a, 0xcd, 0x9e, 0x74, 0x65, 0x9f, 0x2a, 0x68,
    0xbf, 0x6a, 0xe5, 0xf4, 0x02, 0x0c, 0xa7, 0x68, 0x7b, 0x3b, 0xad, 0x61,
    0x11, 0xef, 0x22, 0x9d, 0xdd, 0x9d, 0x7c, 0x3a, 0x5d, 0x23, 0xbd, 0x6b,
    0x95, 0xf5, 0x6d, 0xb7, 0x95, 0x89, 0x10, 0xd0, 0xe9, 0x85, 0x90, 0x45,
    0xe5, 0xbe, 0xc1, 0x9d, 0x40, 0x88, 0x1e, 0x4e, 0x0f, 0x66, 0xfa, 0xb8,
    0xef, 0x5e, 0xe8, 0x3d, 0x71, 0x0d, 0x9f, 0x0a, 0x6b, 0x82, 0x13, 0xa8,
    0x96, 0xfa, 0xad, 0x51, 0x48, 0xfb, 0x8c, 0x94, 0x6c, 0xf0, 0xe9, 0xfb,
    0x9b, 0xf8, 0x50, 0x53, 0x40, 0xf7, 0x30, 0x5c, 0x28, 0xcc, 0xab, 0x59,
    0xa2, 0xc3, 0x4c, 0x65, 0x22, 0x35, 0xb0, 0x5a, 0x88, 0x8c, 0x8a, 0x61,
    0x2b, 0x6b, 0x0e, 0x7e, 0xd5, 0x40, 0x16, 0x87, 0x29, 0x9e, 0x89, 0xbd,
    0x11, 0xa2, 0xc2, 0xc6, 0x02, 0x80, 0x9c, 0xf4, 0x00, 0x41, 0x21, 0x24,
    0x10, 0x31, 0x9c, 0x40, 0xf1, 0xef, 0x7d, 0xeb, 0x8f, 0x08, 0x26, 0x7b,
    0x4e, 0xe9, 0xbf, 0x8c, 0xe4, 0x45, 0xdf, 0xb9, 0x9e, 0xde, 0x68, 0x89,
    0xd6, 0x97, 0xf5, 0x58, 0xa3, 0xde, 0x7c, 0x48, 0xd2, 0x87, 0x9f, 0xb9,
    0x38, 0x0a, 0x87, 0xba, 0xae, 0x4a, 0x94, 0xa6, 0xe5, 0x5d, 0xc1, 0xc9,
    0xac, 0xa3, 0xf9, 0xef, 0xe1, 0x49, 0x9e, 0x60, 0xee, 0xe9, 0x12, 0x12,
    0xbd, 0x4e, 0x3d, 0x38, 0xea, 0x36, 0xc6, 0x9f, 0x81, 0x50, 0x40, 0xbe,
    0xc4, 0x75, 0xc7, 0xda, 0xb3, 0x67, 0x39, 0xdd, 0xb3, 0xa7, 0xf6, 0x63,
    0x46, 0x55, 0x6f, 0x88, 0x7b, 0xfe, 0x84, 0x25, 0x4e, 0x14, 0xad, 0xc6,
    0x9a, 0x1f, 0x8b, 0xa6, 0x3e, 0xeb, 0x31, 0x14, 0x34, 0x3a, 0xfe, 0x67,
    0x0c, 0x0f, 0x7b, 0xde, 0xa5, 0x46, 0xda, 0x96, 0xdd, 0xb3, 0x49, 0xc2,
    0x80, 0x74, 0x7a, 0xbc, 0xdc, 0x7d, 0x93, 0x75, 0x1b, 0x76, 0x73, 0x65,
    0xec, 0x99, 0x52, 0x34, 0xe5, 0x18, 0xfe, 0xee, 0x3c, 0x04, 0x00, 0xf0,
    0x83, 0xbe, 0x0e, 0xae, 0x47, 0xae, 0xbf, 0xbd, 0xd2, 0x18, 0x08, 0x2e,
    0x0a, 0xee, 0xed, 0xcf, 0x3b, 0x7f, 0x44, 0xb8, 0x9f, 0x34, 0x6b, 0xfd,
    0xf8, 0xd0, 0x5a, 0x23, 0xb6, 0xe5, 0xe4, 0xae, 0x3c, 0x33, 0x66, 0x50,
    0xd0, 0x01, 0xf4, 0x36, 0x49, 0x4a, 0x83, 0x90, 0xdf, 0xf1, 0x7f, 0xe7,
    0xb0, 0x35, 0x28, 0xa8, 0x66, 0x4b, 0xde, 0x31, 0x63, 0xeb, 0x83, 0xbd,
    0xa1, 0xd6, 0x9f, 0x2b, 0x72, 0x50, 0xe1, 0x3d, 0xc8, 0xa0, 0x49, 0x60,
    0x98, 0xbb, 0x61, 0xc5, 0x18, 0x7c, 0xac, 0x51, 0xf1, 0x00, 0xbb, 0xec,
    0x54, 0x55, 0x1e, 0xcd, 0xdb, 0xdb, 0x8f, 0x6c, 0x99, 0x69, 0x2e, 0x1d,
    0x22, 0x16, 0xca, 0x18, 0x38, 0x04, 0x23, 0x6d, 0xf7, 0x42, 0x67, 0x1f,
    0x84, 0x80, 0x31, 0x4f, 0xa1, 0xd9, 0x62, 0x20, 0x6f, 0x0f, 0x1d, 0x21,
    0x5e, 0x10, 0x21, 0x8a, 0xf2, 0x91, 0xf6, 0x47, 0xb2, 0x1f, 0x11, 0x72,
    0xee, 0xd4, 0x72, 0xaf, 0x94, 0x32, 0xbe, 0x95, 0x88, 0x24, 0x8f, 0xf3,
    0xeb, 0x1c, 0xa5, 0xe9, 0xb0, 0x0c, 0x71, 0xd5, 0xb8, 0xd4, 0xdd, 0x3e,
    0xb7, 0xf8, 0x12, 0xd0, 0xf0, 0xcf, 0xa4, 0xe2, 0x21, 0x92, 0xf5, 0x20,
    0x3a, 0x34, 0x0f, 0xa4, 0x0c, 0xbb, 0x2f, 0x54, 0x66, 0x19, 0xec, 0xe7,
    0x8a, 0x1c, 0xf3, 0xc3, 0xe1, 0x18, 0x6f, 0x65, 0x7c, 0xde, 0x67, 0x83,
    0x58, 0xee, 0x5c, 0xca, 0x30, 0xf0, 0x23, 0xda, 0xbc, 0x63, 0xe3, 0xab,
    0x88, 0x53, 0x2b, 0x97, 0x7c, 0x40, 0x36, 0xd2, 0xe1, 0x7a, 0xfa, 0x0d,
    0x40, 0xc7, 0x0d, 0x40, 0x45, 0x05, 0xa6, 0x88, 0xad, 0x84, 0x77, 0x3c,
    0x0a, 0xa6, 0x0e, 0x81, 0x99, 0x8c, 0xf0, 0x86, 0xf4, 0xe9, 0x4e, 0x10,
    0x96, 0xe9, 0xfd, 0xfc, 0x34, 0x5f, 0x2e, 0x54, 0x12, 0xad, 0xab, 0x66,
    0xf9, 0xc0, 0x7f, 0x8b, 0x49, 0xac, 0x94, 0x8c, 0x67, 0xea, 0x54, 0x33,
    0x79, 0x36, 0xef, 0x53, 0x52, 0x03, 0x6b, 0x5b, 0x71, 0x65, 0xba, 0xd3,
    0xcc, 0x73, 0x3a, 0x53, 0x29, 0xd8, 0xf5, 0x92, 0x66, 0x2a, 0x63, 0x57,
    0xcd, 0x69, 0x62, 0xa0, 0x69, 0x56, 0x5b, 0xc8, 0xa0, 0x20, 0x5f, 0x12,
    0x9a, 0x32, 0xfb, 0x63, 0x08, 0xee, 0xf1, 0x00, 0x74, 0x4f, 0x71, 0xf4,
    0x0c, 0x94, 0x2d, 0xa1, 0x40, 0x0b, 0x11, 0xa7, 0x57, 0x62, 0x60, 0x79,
    0x7e, 0xdc, 0xdc, 0x02, 0x22, 0xa8, 0x8b, 0xb6, 0xb5, 0x45, 0x7d, 0xfd,
    0x8f, 0x80, 0x56, 0x7c, 0xdb, 0x3d, 0x89, 0xe0, 0x8d, 0x9f, 0x38, 0x52,
    0x81, 0x1c, 0xc9, 0xee, 0xf4, 0x7f, 0xcd, 0x60, 0x21, 0x52, 0x9b, 0x36,
    0x23, 0x55, 0x63, 0x24, 0x6b, 0x68, 0x87, 0x22, 0x19, 0xe9, 0x1a, 0x66,
    0x69, 0x18, 0x99, 0x5a,
};
static std::uint8_t ct[1024] = {
    0xdb, 0x97, 0x26, 0x2d, 0x0e, 0x73, 0xe6, 0x63, 0xfe, 0xc5, 0xdc, 0x46,
    0xff, 0x41, 0x9b, 0xf1, 0x7e, 0x62, 0x87, 0x5e, 0xd6, 0x41, 0x77, 0x26,
    0xbb, 0x00, 0xf0, 0xc8, 0x11, 0xda, 0x0f, 0xab, 0x9c, 0x4d, 0x35, 0xd5,
    0x96, 0x30, 0xb6, 0x40, 0xf5, 0x14, 0x71, 0x42, 0x9a, 0x8b, 0x84, 0x85,
    0x6b, 0xd6, 0xe9, 0xba, 0x26, 0x74, 0x39, 0xab, 0x06, 0xf0, 0xef, 0x00,
    0x6c, 0xaf, 0xbf, 0x5e, 0x7c, 0x0c, 0xfb, 0x30, 0x5f, 0x0b, 0x61, 0x78,
    0x91, 0x3a, 0x12, 0x9d, 0xe6, 0x66, 0xf0, 0x9a, 0xab, 0xac, 0xc7, 0x54,
    0x45, 0x44, 0xb4, 0x90, 0x27, 0x48, 0x73, 0x97, 0xfc, 0x52, 0xcf, 0x5d,
    0xd9, 0xa8, 0x41, 0xd1, 0x5f, 0x04, 0xcc, 0x22, 0x55, 0xd0, 0x6c, 0x94,
    0xa2, 0xbd, 0x41, 0x9a, 0xe0, 0xde, 0x2b, 0x5b, 0x3d, 0x34, 0x19, 0x14,
    0xf8, 0xab, 0xba, 0x13, 0xf0, 0xb3, 0x9d, 0xdc, 0xe5, 0xdf, 0x6b, 0x97,
    0x93, 0x17, 0x6e, 0x41, 0x0a, 0xbf, 0x44, 0xe7, 0x2f, 0x37, 0xa4, 0xc7,
    0x36, 0xaa, 0xc7, 0x67, 0x2a, 0x45, 0x7f, 0xbf, 0xbf, 0x45, 0xfb, 0xca,
    0x8e, 0x7c, 0x7d, 0xae, 0x57, 0x32, 0xc7, 0x89, 0x29, 0x94, 0x03, 0x9c,
    0x18, 0xd3, 0x20, 0x9c, 0xd0, 0x4e, 0x9b, 0x14, 0xd0, 0xf6, 0x3f, 0x2a,
    0x3c, 0xe6, 0x29, 0xfb, 0xa8, 0x9f, 0xb4, 0x78, 0x31, 0xe0, 0x52, 0x7e,
    0xde, 0x30, 0x6b, 0x2d, 0xfa, 0x5b, 0xe3, 0x35, 0xf5, 0x5a, 0x2e, 0xbd,
    0x8f, 0xfe, 0x4e, 0x24, 0x12, 0x2a, 0xae, 0xf0, 0x90, 0x14, 0xe8, 0xc9,
    0xe8, 0x8a, 0xa4, 0x99, 0xab, 0xa3, 0xc2, 0x15, 0xf4, 0x07, 0xe4, 0x15,
    0x6c, 0x67, 0x16, 0xf4, 0xd3, 0x9f, 0x97, 0x95, 0x54, 0xa5, 0x4a, 0xe3,
    0x71, 0xb5, 0x0d, 0x49, 0xb9, 0x7d, 0x4c, 0x13, 0xad, 0x06, 0x3c, 0xb2,
    0x71, 0x36, 0xd2, 0xbb, 0xe5, 0x3d, 0x9d, 0x52, 0x07, 0x88, 0xdb, 0xae,
    0x66, 0xaf, 0xa4, 0x11, 0x3e, 0xe9, 0x02, 0x9e, 0x3e, 0xf4, 0xf8, 0xf6,
    0x1e, 0xc1, 0xab, 0x9b, 0x59, 0x60, 0x5b, 0x7f, 0xa1, 0x15, 0xaf, 0x65,
    0x90, 0x0c, 0xbd, 0x05, 0x19, 0xe8, 0x77, 0xda, 0xc0, 0x2d, 0x93, 0x5b,
    0xf8, 0xbc, 0xdd, 0x81, 0x7a, 0xca, 0xd8, 0x8f, 0x59, 0xbb, 0x3a, 0xb3,
    0x62, 0x21, 0x95, 0xac, 0xae, 0x43, 0x1b, 0x45, 0x09, 0x80, 0x7d, 0xea,
    0xcd, 0x76, 0xc7, 0x85, 0xdc, 0x83, 0x04, 0xd7, 0xd6, 0x32, 0x3d, 0x78,
    0x83, 0x3f, 0x87, 0x93, 0xef, 0x42, 0xf7, 0x8b, 0xc0, 0xfc, 0x8f, 0xfe,
    0x8e, 0x6a, 0xc1, 0x86, 0x97, 0x9c, 0x4e, 0x25, 0x46, 0x99, 0x01, 0xda,
    0x77, 0x3a, 0x0b, 0x29, 0x89, 0x7c, 0x68, 0x27, 0x71, 0xda, 0xa6, 0x77,
    0xbb, 0x62, 0x01, 0xa0, 0x35, 0x6c, 0x0e, 0xcd, 0x7c, 0xf4, 0x8b, 0x78,
    0xb9, 0x23, 0xf8, 0x07, 0x5c, 0xa6, 0x88, 0x43, 0xa3, 0x84, 0x30, 0xef,
    0x9d, 0x31, 0xd7, 0xa3, 0x9c, 0xf9, 0x1f, 0x1f, 0x16, 0x79, 0x00, 0x7e,
    0xb4, 0xf2, 0x9a, 0xa1, 0xe8, 0x5e, 0x20, 0x87, 0x02, 0xe3, 0x42, 0x90,
    0x62, 0x72, 0xe4, 0x8e, 0x3e, 0x71, 0xb2, 0x7a, 0x7f, 0x57, 0xa4, 0x1b,
    0xdc, 0xba, 0xca, 0x29, 0x7d, 0xc9, 0xd0, 0xae, 0x9f, 0x50, 0x79, 0x68,
    0x09, 0x7a, 0x47, 0x29, 0x4a, 0x8f, 0xbf, 0xb3, 0xec, 0xc0, 0x27, 0xa8,
    0x1f, 0xf6, 0x8a, 0xea, 0x15, 0xfb, 0xf1, 0xdb, 0x96, 0x80, 0xe9, 0xbb,
    0x93, 0x52, 0x2e, 0x47, 0xa8, 0xa6, 0x38, 0xaf, 0xb7, 0x3d, 0x00, 0xff,
    0x2c, 0x16, 0x54, 0xde, 0xaa, 0xdb, 0x32, 0xa8, 0x7f, 0xc5, 0x4e, 0x6c,
    0x11, 0x62, 0x8c, 0x42, 0xe8, 0x8a, 0x1e, 0x8a, 0x1d, 0xcd, 0x61, 0x5f,
    0xbf, 0x9c, 0x37, 0x61, 0x68, 0x1d, 0x8d, 0x54, 0xeb, 0xb0, 0x9e, 0xca,
    0x2b, 0x89, 0xac, 0x32, 0x37, 0x4c, 0xbd, 0x12, 0xde, 0x8e, 0xfe, 0x32,
    0x5e, 0x1d, 0xf9, 0xfc, 0x4c, 0x45, 0x78, 0x7a, 0x8c, 0x6a, 0xcc, 0xc1,
    0xb8, 0x90, 0x2e, 0x4a, 0xaf, 0xf9, 0x7c, 0x12, 0x52, 0x85, 0x99, 0xfe,
    0x77, 0x11, 0x88, 0xbd, 0x02, 0x5a, 0xed, 0x99, 0xb3, 0xbf, 0x73, 0xe1,
    0xc2, 0xc9, 0x37, 0x92, 0xbe, 0xec, 0x0c, 0xcd, 0xfd, 0x6e, 0xe4, 0x70,
    0xd7, 0x6b, 0x51, 0x36, 0xb4, 0x43, 0xe9, 0xa1, 0xac, 0x4c, 0x29, 0x1e,
    0x7d, 0x54, 0xe5, 0xe8, 0xbe, 0x66, 0xfd, 0x4b, 0x87, 0xd1, 0xcb, 0x87,
    0x01, 0xb9, 0x5e, 0x08, 0x37, 0x16, 0x1f, 0xfd, 0xdd, 0xc5, 0x25, 0x6c,
    0x9c, 0x48, 0xa6, 0x5c, 0x21, 0x00, 0x42, 0x28, 0x18, 0x90, 0x2a, 0xb7,
    0x30, 0x8e, 0x1d, 0x64, 0x40, 0xd1, 0x1d, 0x13, 0x21, 0x8b, 0x27, 0x91,
    0x70, 0xc0, 0xae, 0x91, 0xb5, 0xb9, 0x35, 0xac, 0xc9, 0xbb, 0xb1, 0xac,
    0x32, 0x64, 0xdf, 0x40, 0x84, 0x02, 0x6a, 0xe5, 0x46, 0x99, 0x68, 0x25,
    0xe8, 0xb9, 0xd1, 0x98, 0xce, 0x81, 0xd5, 0x6f, 0x86, 0xb2, 0x54, 0x6b,
    0xe0, 0x11, 0x95, 0x1f, 0x9b, 0x1e, 0x18, 0x8e, 0x17, 0xad, 0xb1, 0x2d,
    0x52, 0x46, 0x6f, 0x58, 0xb2, 0xef, 0xc4, 0x23, 0xc7, 0x95, 0xd0, 0xff,
    0x86, 0x2a, 0x08, 0x9a, 0xbb, 0xad, 0x2f, 0xf7, 0xce, 0xc9, 0x40, 0x45,
    0xce, 0x40, 0x3e, 0x8b, 0x9e, 0x84, 0xf4, 0x52, 0xbc, 0xde, 0xb5, 0x14,
    0x19, 0x3e, 0xcc, 0x70, 0x49, 0x7a, 0x10, 0x0f, 0x62, 0xb4, 0x06, 0xc9,
    0xb8, 0x0a, 0x49, 0x8d, 0xf4, 0xea, 0xdb, 0x7e, 0x78, 0x19, 0xdd, 0xf3,
    0x63, 0x90, 0x81, 0xd2, 0x66, 0xc5, 0x87, 0x8f, 0xb0, 0x1d, 0x6b, 0xa3,
    0x9c, 0x92, 0xb0, 0x15, 0xd0, 0x33, 0x9e, 0xcb, 0x52, 0xcc, 0x60, 0x69,
    0x0b, 0x5f, 0x66, 0x59, 0xc0, 0xf3, 0x3f, 0xb6, 0xe2, 0x6f, 0xbe, 0x85,
    0xd9, 0x25, 0x15, 0xa1, 0xe9, 0x3b, 0x0e, 0xed, 0x88, 0x08, 0x30, 0x36,
    0xd7, 0x93, 0x80, 0x27, 0xe5, 0x7a, 0x66, 0x03, 0xce, 0x87, 0x06, 0x9e,
    0xc1, 0x99, 0x22, 0x3a, 0xf2, 0x3e, 0xb4, 0xaa, 0xc9, 0x76, 0x38, 0xd1,
    0x88, 0x2f, 0x61, 0x8e, 0xd2, 0xf7, 0x91, 0x38, 0x6c, 0x90, 0x01, 0x34,
    0xb9, 0xa8, 0x5f, 0x11, 0x25, 0xe9, 0x75, 0x15, 0x3b, 0x81, 0xa7, 0x44,
    0x90, 0x93, 0xd3, 0xb2, 0xec, 0x81, 0xad, 0x8f, 0x07, 0x9c, 0x1b, 0x40,
    0xfe, 0x47, 0xe5, 0x84, 0x38, 0xbd, 0x00, 0x36, 0xc4, 0xa5, 0x01, 0x2f,
    0x1a, 0xde, 0xca, 0x19, 0x1c, 0x74, 0x86, 0xd9, 0xfe, 0xc6, 0xd7, 0x1c,
    0x4d, 0xf3, 0x7b, 0x22, 0x5b, 0xe9, 0x2b, 0x58, 0x5d, 0x45, 0x1e, 0x2d,
    0x56, 0x1c, 0x4f, 0xd5, 0x67, 0x4c, 0x12, 0x79, 0xc5, 0xfb, 0x5c, 0x04,
    0x7f, 0x09, 0xe6, 0x75, 0xeb, 0x14, 0x01, 0x7c, 0x03, 0xbe, 0x33, 0x9b,
    0x50, 0x33, 0x95, 0x9d, 0xba, 0x83, 0x6b, 0x03, 0xbf, 0xd6, 0xc7, 0x39,
    0xf6, 0xca, 0xbd, 0x7e, 0x7f, 0x71, 0x71, 0xff, 0xa1, 0x10, 0x89, 0x88,
    0xac, 0x51, 0x83, 0x80, 0x53, 0x7f, 0x2f, 0xa1, 0xe9, 0x55, 0x06, 0xbb,
    0xd7, 0xc4, 0xf5, 0xe4, 0xbe, 0x40, 0x54, 0xaa, 0x48, 0x2d, 0xe9, 0x8c,
    0xe9, 0x76, 0xf2, 0x20, 0xc2, 0x72, 0x32, 0x2d, 0xfe, 0x67, 0x4c, 0xb4,
    0x15, 0x62, 0x08, 0x07, 0x2f, 0x48, 0x67, 0xa5, 0xf0, 0x06, 0xa2, 0x2d,
    0xa3, 0xd1, 0xfc, 0xdb, 0x80, 0x6b, 0x10, 0xfe, 0x3e, 0x7a, 0x0c, 0xe4,
    0xcc, 0xc8, 0x3e, 0x45, 0x18, 0x0c, 0xa7, 0x3d, 0x6c, 0x75, 0xe9, 0x27,
    0x4f, 0x59, 0x31, 0x6f, 0xe5, 0xce, 0xb7, 0x71, 0xe8, 0xc5, 0x08, 0xb7,
    0x7e, 0xd9, 0x8f, 0x5c,
};
static std::uint8_t tag[16] = {
    0xb5, 0x72, 0x83, 0xb0, 0xbf, 0x10, 0x16, 0x33,
    0xa5, 0x0b, 0x8f, 0x80, 0x1b, 0xcc, 0xec, 0x13,
};

void test_gcm_mode()
{
    std::uint8_t buf[1024], get_tag[16];
    std::size_t  size, n;

    auto e = SM4GcmEncryptor(user_key, iv, 16, aad, 16);
    e.do_final(buf, &size, pt, 1024);
    e.get_tag(get_tag);
    if (std::memcmp(buf, ct, 1024) != 0 || size != 1024 ||
        std::memcmp(tag, get_tag, 16) != 0)
    {
        throw std::runtime_error("err in gcm_mode");
    }
    e.reset(iv, 16, aad, 16);
    e.do_final(buf, &size, pt, 1024);
    e.get_tag(get_tag);
    if (std::memcmp(buf, ct, 1024) != 0 || size != 1024 ||
        std::memcmp(tag, get_tag, 16) != 0)
    {
        throw std::runtime_error("err in gcm_mode");
    }
    e = SM4GcmEncryptor(user_key, iv, 16, aad, 16);
    e.update(buf, &n, pt, 100);
    size = n;
    e.do_final(buf + size, &n, pt + 100, 1024 - 100);
    size += n;
    e.get_tag(get_tag);
    if (std::memcmp(buf, ct, 1024) != 0 || size != 1024 ||
        std::memcmp(tag, get_tag, 16) != 0)
    {
        throw std::runtime_error("err in gcm_mode");
    }
    e = SM4GcmEncryptor(user_key, iv, 16, aad, 16);
    e.update(buf, &n, pt, 100);
    size = n;
    e.update(buf + size, &n, pt + 100, 1024 - 100);
    size += n;
    e.do_final(buf + size, &n, nullptr, 0);
    size += n;
    e.get_tag(get_tag);
    if (std::memcmp(buf, ct, 1024) != 0 || size != 1024 ||
        std::memcmp(tag, get_tag, 16) != 0)
    {
        throw std::runtime_error("err in gcm_mode");
    }

    auto d = SM4GcmDecryptor(user_key, iv, 16, aad, 16);
    d.set_tag(tag);
    d.do_final(buf, &size, ct, 1024);
    if (std::memcmp(buf, pt, 1024) != 0 || size != 1024)
    {
        throw std::runtime_error("err in gcm_mode");
    }
    d.reset(iv, 16, aad, 16);
    d.set_tag(tag);
    d.do_final(buf, &size, ct, 1024);
    if (std::memcmp(buf, pt, 1024) != 0 || size != 1024)
    {
        throw std::runtime_error("err in gcm_mode");
    }
    d = SM4GcmDecryptor(user_key, iv, 16, aad, 16);
    d.set_tag(tag);
    d.update(buf, &n, ct, 100);
    size = n;
    d.do_final(buf + size, &n, ct + 100, 1024 - 100);
    size += n;
    if (std::memcmp(buf, pt, 1024) != 0 || size != 1024)
    {
        throw std::runtime_error("err in gcm_mode");
    }
    d = SM4GcmDecryptor(user_key, iv, 16, aad, 16);
    d.set_tag(tag);
    d.update(buf, &n, ct, 100);
    size = n;
    d.update(buf + size, &n, ct + 100, 1024 - 100);
    size += n;
    d.do_final(buf + size, &n, nullptr, 0);
    size += n;
    if (std::memcmp(buf, pt, 1024) != 0 || size != 1024)
    {
        throw std::runtime_error("err in gcm_mode");
    }
}